<template>
  <div>
    <el-dialog
      title="编辑信息"
      :visible="dialogVisible"
      :show-close="false"
      width="550px"
    >
      <el-form
        ref="customerDialog"
        :model="row"
        :rules="rules"
        label-width="85px"
      >
        <el-form-item label="预约时间:" prop="ordertime">
          <el-date-picker
            v-model="row.ordertime"
            type="datetime"
            size="medium"
            placeholder="请选择日期"
          />
        </el-form-item>
        <el-form-item label="备注:" prop="des" style="width: 450px;">
          <el-input
            v-model="row.des"
            rows="4"
            type="textarea"
            size="medium"
            placeholder="请输入备注"
          />
        </el-form-item>
      </el-form>
      <span slot="footer">
        <el-button
          @click="handleCancel"
        >
          取 消
        </el-button>
        <el-button
          type="primary"
          @click="handleConfirm"
        >
          确 定
        </el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: 'CustomerDialog',
  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    },
    row: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  data() {
    return {
      rules: {
        ordertime: [
          {
            type: 'date',
            required: true,
            message: '请选择日期',
            trigger: 'change'
          }
        ]
      }
    }
  },
  methods: {
    handleCancel() {
      this.$emit('cancel-dialog')
      this.$refs.customerDialog.resetFields()
    },
    handleConfirm() {
      this.$refs.customerDialog.validate((valid) => {
        if (valid) {
          this.$emit('confirm-dialog', {
            id: this.row.id,
            ordertime: this.row.ordertime ? this.$moment(this.row.ordertime).format('YYYY-MM-DD HH:mm:ss') : '',
            des: this.row.des
          })
          this.$refs.customerDialog.resetFields()
        } else {
          return false
        }
      })
    }
  }
}
</script>

<style scoped>
</style>
